package fortunata.fswapps.helloWorld;

import com.ecyrd.jspwiki.WikiContext;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.vocabulary.RDFS;
import fortunata.FortunataSWApplication;

import java.util.GregorianCalendar;

/**
 * The Fortunata-based Application HelloWorld
 */
public class HelloWorldSWApp extends FortunataSWApplication {

    public static final String propNameMsg = "hwProperty";

    public HelloWorldSWApp(){
         initialize("helloWorld.model.owl",
                    "helloWorld.data.owl",
                    "http://ishtar.ii.uam.es/ontologies/helloWorld/20080910",
                    "helloWorld",
                    "HelloWorld",
                    "HelloWorldOntology");
    }

    public String getInstanceUniqueURI(){
        return getURI() + new GregorianCalendar().getTimeInMillis();
    }

    public void createIndividual (WikiContext context, OntModel m, Individual indl){
        Property pLiteral = m.getProperty(getURI() + propNameMsg);
        String msg = "Hello World!";
        indl.setPropertyValue(pLiteral, m.createLiteral(msg));
    }

    public void fillDataModel(OntModel m){
        String URI =getURI();
        //Creates a class
        OntClass c1ass = m.createClass(URI + getMainClassName());

        //Creates a datatypeProperty
        DatatypeProperty propHW = m.createDatatypeProperty(URI + propNameMsg);
        propHW.setDomain(c1ass);
        propHW.setRange(RDFS.Literal);
    }
}
